

from rest_framework import serializers
from goods.models import SPU,Brand



class BrandSimpleModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields = [
            'id',
            'name'
        ]


class SPUDetailModelSerializer(serializers.ModelSerializer):
    brand = serializers.StringRelatedField() # 默认只参与序列化
    brand_id = serializers.IntegerField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()

    class Meta:
        model = SPU
        fields = '__all__'

        # 把category1，category2和category3修改为只参与序列化操作
        extra_kwargs = {
            'category1': {"read_only": True},
            'category2': {"read_only": True},
            'category3': {"read_only": True},
        }











